package control;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import model.Box;



public class BoxDataModel  extends ListDataModel<Box> implements SelectableDataModel<Box>,Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public BoxDataModel(){
		
	}
	public BoxDataModel(List<Box>data){
		super(data);  
	}
	
    @Override  
    public Box getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<Box> caixas = (List<Box>)this.getWrappedData();  
          
        for(Box cx : caixas) {  
            String id = ""+cx.getIdBox();  
            if(id.equals(rowKey))  
                return cx;  
        }  
          
        return null;  
    }  
    
     @Override  
    public Object getRowKey(Box obj) {  
        return ""+obj.getIdBox();  
    }  
  

}
